﻿define(['util', 'ajax'], function (util, ajax) {
    "use strict";

    var exports = {},
         ViewModel;


    ViewModel = function () {
        var self = this;

        self.code = ko.observable();
        self.name = ko.observable();
        self.dateOfBirth = ko.observable();
        self.address = ko.observable();
        self.emailaddress = ko.observable();
        self.mobilenumber = ko.observable();

        self.register = function () {
            var form = {
                Code: self.code(),
                Name: self.name(),
                DateOfBirth: moment(self.dateOfBirth()).toISOString(),
                Address: self.address(),
                Email: self.emailaddress(),
                Mobile: self.mobilenumber(),
            };

            ajax.post('MemberRegistration', form).done(function (response) {
                if (response.isSuccess == true) {
                    util.notify.info("Your registration successfully, Please check you mail");
                    self.clear();
                }
            });
        };
    };

    exports.exec = function (model) {
        var viewModel = new ViewModel(model);
        ko.applyBindings(viewModel, document.getElementById('register-form'));
    };

    return exports;
});